package com.family.web.controller.pedigree;


import com.family.common.annotation.Log;
import com.family.common.core.controller.BaseController;
import com.family.common.core.domain.AjaxResult;
import com.family.common.core.page.TableDataInfo;
import com.family.common.enums.BusinessType;
import com.family.pedigree.domain.FamilyTree;
import com.family.pedigree.service.IFamilyTreeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 家族树 前端控制器
 * </p>
 *
 * @author forever
 * @since 2024-11-24
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/family/tree")
public class FamilyTreeController extends BaseController {

    private final IFamilyTreeService familyTreeService;

    @Log(title = "添加家族树", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FamilyTree tree) {
        familyTreeService.add(tree);
        return success();
    }

    @Log(title = "修改家族树", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FamilyTree tree) {
        familyTreeService.edit(tree);
        return success();
    }

    @GetMapping("/list")
    public TableDataInfo getList(FamilyTree tree) {
        startPage();
        return getDataTable(familyTreeService.getList(tree));
    }


    /**
     * 代级
     */
    @GetMapping("/rank")
    public AjaxResult getRankList(){
        return AjaxResult.success(familyTreeService.getRankList());
    }

    @DeleteMapping("/{familyName}")
    public AjaxResult delete(@PathVariable String familyName) {
        familyTreeService.delByFamilyName(familyName);
        return success();
    }
}
